import { getDictTreeList, getDictTree, getDictTreeTree, delDictTree, saveDictTree, updateDictTree } from '@/api/sys/dictTree'

const actions = {
  
  // 获取字段数列表列表
  getDictTreeList({ commit }, param) {
    return new Promise((resolve, reject) => {
      getDictTreeList(param).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  /** 修改/添加时弹出树 */
  getDictTreeTree({ commit }, param) {
    return new Promise((resolve, reject) => {
      getDictTreeTree(param).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  getDictTree({ commit }, id) {
    return new Promise((resolve, reject) => {
      getDictTree(id).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  updateDictTree({ commit }, param) {
    return new Promise((resolve, reject) => {
      updateDictTree(param).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  /**
   * 保存字典树
   * @param {字典树} data
   */
  saveDictTree({ commit }, param) {
    return new Promise((resolve, reject) => {
      saveDictTree(param).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  /**
   *  删除字典树
   * @param {id} id
   */
  delDictTree({ commit }, id) {
    return new Promise((resolve, reject) => {
      delDictTree(id).then(res => {
        resolve()
      }).catch(error => {
        reject(error)
      })
    })
  }

}

export default {
  namespaced: true,
  actions
}
